{extend name="base/common"}

{block name="style"}
<link href="/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
<!-- Sweet Alert -->
<link href="/admin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<!-- Ladda style -->
<link href="/admin/css/plugins/ladda/ladda-themeless.min.css" rel="stylesheet">
{/block}

{block name="page-header"}
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>通讯录</h2>
        <ol class="breadcrumb">
            <li>
                <a href="index.html">Wechat</a>
            </li>
            <li class="active">
                <strong>User</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">

    </div>
</div>
{/block}

{block name="main"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title"><form method="get" action="">
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input type="text" placeholder="用户名" class="input-sm form-control" name="name" value="{notempty name='Think.get.name'}{$Think.get.name}{/notempty}">
                            <span class="input-group-btn">
                                <button type="submit" class="btn btn-sm btn-primary">查询</button>
                            </span>
                        </div>
                    </div></form>

                    <div class="ibox-tools progress-demo">
                        <div class="ladda-button ladda-button-user btn btn-sm
                        btn-primary" >
                            <input type="file" name="excel" id="excel" style="width:100%;height:100%;position: absolute; opacity: 0"/>
                            Excel导入
                        </div>
                        <a data-toggle="modal" class="btn btn-sm btn-primary" href="/admin/wechat/add_user">添加用户</a>

                    </div>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th><input class="i-checks check-all" type="checkbox"></th>
                                <th>ID</th>
                                <td>名称</td>
                                <th>性别 </th>
                                <th>手机号码</th>
                                <th>是否党员</th>
                                <th>所属部门</th>
                                <th>权限</th>
                                <!--<th>状态</th>-->
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td><input type="checkbox" class="i-checks ids" name="input[]"></td>
                                <td>{$vo.id}</td>
                                <td>{$vo.name}</td>
                                <td>{$vo.gender|gender_change}</td>
                                <td>{$vo.mobile}</td>
                                {eq name="$vo.party" value="1"}
                                <td>是</td>
                                {else/}
                                <td>否</td>
                                {/eq}
                                <td>{$vo.department|depart_change}</td>
                                <td>
                                    {eq name="vo.review" value="0"}
                                    <span class="label label-info">普通用户</span>
                                    {else/}
                                    <span class="label label-danger">管理员</span>
                                    {/eq}
                                </td>
                                <!--<td>{eq name="vo.userid" value=""}-->
                                    <!--<span class="label label-warning">未关注</span>-->
                                    <!--{else/}-->
                                    <!--<span class="label label-info">已使用</span>-->
                                    <!--{/eq}-->
                                <!--</td>-->
                                <td>
                                    <a href="{:Url('Wechat/add_user?id='.$vo.id)}">修改</a>
                                    <a href="{:Url('Wechat/del_user?id='.$vo.id) }"  class="confirm ajax-del">删除</a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="11">
                                    <div class="page">{$list->render()}</div>
                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script src="/admin/js/plugins/iCheck/icheck.min.js"></script>
<script src="/admin/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="/admin/js/plugins/ladda/spin.min.js"></script>
<script src="/admin/js/plugins/ladda/ladda.min.js"></script>
<script src="/admin/js/plugins/ladda/ladda.jquery.min.js"></script>
<script>
    $('#excel').change(function(){
        var l = $( '.ladda-button-user' ).ladda();
        l.ladda( 'start' );
        var formData = new FormData();
        formData.append('excel', $(this)[0].files[0]);
        $.ajax({
            type: "post",
            url: "{:Url('Wechat/inserExcel')}",
            data:formData,
            processData : false,
            contentType : false,
            success: function (data) {
                console.log(data);
                if(data.code == 1){
                    updateAlert(data.msg, 'success');
                }else{
                    updateAlert(data.msg, 'error');
                }
                setTimeout(function(){
//                    location.reload();
                },2000);
            }
        });
    });

//    var l = $( '.ladda-button-user' ).ladda();
//    l.click(function(){
//        l.ladda( 'start' );
//        $('#excel')[0].focus();
//        $.ajax({
//            type: "get",
//            url: "{:Url('Wechat/synchronizeUser')}",
//            success: function (response) {
//                swal(response.msg, response.data);
//                l.ladda('stop');
//            },
//            error: function (err) {
//                l.ladda('stop');
//            }
//        });
//    });
</script>
{/block}